package cn.glutnn.service.impl;

import cn.glutnn.entity.Finance;
import cn.glutnn.entity.Result;
import cn.glutnn.mapper.FinancingIntentionMapper;
import cn.glutnn.service.FinancingIntentionService;
import cn.glutnn.utils.ThreadLocalUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import cn.glutnn.entity.FinancingIntention;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * (FinancingIntention)表服务实现类
 *
 * @author msh
 * @since 2024-10-25 09:34:28
 */
@Service
public class FinancingIntentionServiceImpl extends ServiceImpl<FinancingIntentionMapper, FinancingIntention> implements FinancingIntentionService {



    @Override
    public Result<List<FinancingIntention>> selectIntentionByName() {
        Map o = ThreadLocalUtil.get();
        List<FinancingIntention> list = list(new QueryWrapper<FinancingIntention>().eq("user_name", o.get("username")));
        return Result.success(list);
    }


    public FinancingIntention selectIntentionByName(String name) {
        Map o = ThreadLocalUtil.get();
        return getOne(new QueryWrapper<FinancingIntention>().eq("user_name", name));
    }

    @Override
    public Result<FinancingIntention> insertIntentionByName(FinancingIntention financingIntention) {
        Map o = ThreadLocalUtil.get();
        financingIntention.setUserName(o.get("username").toString());
        System.out.println(o.get("username"));
        financingIntention.setCreateTime(new Date());
        financingIntention.setUpdateTime(new Date());
        boolean save = save(financingIntention);
        return Result.success();
    }

    @Override
    public Result<FinancingIntention> updateIntentionByName(FinancingIntention financingIntention) {
        financingIntention.setUpdateTime(new Date());
        Map o = ThreadLocalUtil.get();
        boolean update = update(financingIntention, new UpdateWrapper<FinancingIntention>().eq("user_name", o.get("username")));

        return Result.success();
    }

    @Override
    public Result<FinancingIntention> deleteIntentionByName() {
        Map o = ThreadLocalUtil.get();
        boolean remove = remove(new QueryWrapper<FinancingIntention>().eq("user_name", o.get("username")));
        return Result.success();
    }

}

